package com.kinghood.productcenter.controller.base;

import com.kinghood.infrastructure.api.authority.SysLogModuleEnum;
import com.kinghood.infrastructure.aspect.OperatorLog;
import com.kinghood.infrastructure.model.KingHoodResponseVO;
import com.kinghood.productcenter.common.model.dto.MoveChangeSortReqDTO;
import com.kinghood.infrastructure.model.dto.StatusReqDTO;
import com.kinghood.productcenter.common.model.dto.base.GoodsQueryDTO;
import com.kinghood.productcenter.common.model.dto.base.GoodsReqDTO;
import com.kinghood.productcenter.service.base.IBaseGoodsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * <p>
 * 基础选项-货类 前端控制器
 * </p>
 *
 * @author KingHood
 * @since 2023-12-20
 */
@RestController
@RequestMapping("/baseGoods")
public class BaseGoodsController {
    @Resource
    private IBaseGoodsService goodsService;

    @PostMapping("/listAllGoods")
    public KingHoodResponseVO listAllGoods(@RequestBody GoodsQueryDTO param) {
        return KingHoodResponseVO.success(goodsService.listAllGoods(param));
    }

    /**
     * 新增更新
     *
     * @param param
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_GOODS,content = "货类管理-新增、修改")
    @PostMapping("/addOrUpdateGoods")
    public KingHoodResponseVO addOrUpdateGoods(@Valid @RequestBody GoodsReqDTO param) {
        goodsService.addOrUpdateGoods(param);
        return KingHoodResponseVO.success();
    }

    /**
     * 更新状态
     *
     * @param param 参数
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_GOODS,content = "货类管理-修改状态")
    @PostMapping("/updateGoodsStatus")
    public KingHoodResponseVO updateGoodsStatus(@Valid @RequestBody StatusReqDTO param) {
        goodsService.updateGoodsStatus(param);
        return KingHoodResponseVO.success();
    }

    /**
     * 根据id删除
     *
     * @param id id
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_GOODS,content = "货类管理-删除")
    @RequestMapping("/delGoods/{id}")
    public KingHoodResponseVO delGoods(@PathVariable("id") Long id) {
        goodsService.delGoods(id);
        return KingHoodResponseVO.success();
    }

    /**
     * 详细
     *
     * @param id id
     * @author jp
     * @date 2023/12/28
     */
    @GetMapping(value = "/detailGoods/{id}")
    public KingHoodResponseVO detailGoods(@PathVariable("id") Long id){
        return KingHoodResponseVO.success(goodsService.detailGoods(id));
    }

    /**
     * 拖动更改排序
     *
     * @param param 参数
     * @author jp
     * @date 2023/12/27
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_GOODS,content = "货类管理-修改排序")
    @PostMapping("/changeSort")
    public KingHoodResponseVO changeSort(@Valid @RequestBody MoveChangeSortReqDTO param) {
        goodsService.changeSort(param);
        return KingHoodResponseVO.success();
    }

    /**
     * 下载商品
     *
     * @param param 参数
     * @author jp
     * @date 2024/01/04
     */
    @PostMapping("/downloadGoods")
    public void downloadGoods(@RequestBody GoodsQueryDTO param, HttpServletResponse response) {
        goodsService.downloadGoods(param, response);
    }
}
